clc
clear

nvars = 9;
nobjs = 2;

constX = [50e6,8];
constX = parallel.pool.Constant(constX);
% powerNominalCharge, chargingHours
lowbound = [1e2, 1e2, 1e2, 502 + 273.15, -150 + 273.15, 300 + 273.15, -78 + 273.15, 1.5, -0.001];
upperbound = [1e9, 1e9, 1e9, 580 + 273.15, -82 + 273.15, 498 + 273.15, 0 + 273.15, 10, 0.001];
%  UA_Reg, UA_Hot, UA_Cold, T1Charge, T4Charge, T1Discharge, T4Discharge, pressureRatio, capacityMassGain

objfun = @(x) functionBPTES_exergy(x, constX.Value);

delete(gcp('nocreate'));
parpool;

populationSize = 1000;
generations = 500;

load('pic\07-02_09.mat')
[x0, fval0] = initialize(x, fval, populationSize);

options = optimoptions('gamultiobj', 'Display', 'iter', ...
    'PopulationSize', populationSize, ...
    'MaxGenerations', generations, ...
    'UseParallel', true, ...
    'InitialPopulationMatrix', x0);

[x, fval] = gamultiobj(objfun, nvars, [], [], [], [], lowbound, upperbound, options);

delete(gcp('nocreate'));

%%
plot(fval(:,2), fval(:,1), 'o');
xlabel('总cost（欧元）');
ylabel('Round Trip Efficiency');
title('Pareto Front');
grid on

timestamp = datetime('now', 'Format', 'MM-dd_HH');
folder = 'pic';
if ~exist(folder, 'dir')
    mkdir(folder);
end
filename = fullfile(folder, [char(timestamp), '.fig']);
saveas(gcf, filename);

dataFilename = fullfile(folder, [char(timestamp), '.mat']);
save(dataFilename, 'x', 'fval');


